import { Ref, ref, watch } from "vue";
import { patrolingVoice } from "@/api/remote-control.js";

/*
 * @Author: ReinerLau lk850593913@gmail.com
 * @Date: 2023-01-31 16:44:42
 * @LastEditors: ReinerLau lk850593913@gmail.com
 * @LastEditTime: 2023-02-15 08:53:07
 * @FilePath: \v2.0.0\src\views\patroling\composables\useVoiceControl.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
interface Options {
  caritem: Ref<string>;
}
export default (options: Options) => {
  const { caritem } = options;
  const voice = ref(false);
  watch(voice, (newVal) => {
    toggleVoice(newVal);
  });
  function toggleVoice(newVal) {
    const data = {
      rid: caritem.value,
      type: newVal ? "0" : "1",
    };
    patrolingVoice(data);
  }

  return {
    voice,
  };
};
